"""
# -*- coding: UTF-8 -*-
# Author:yangshuoshuo
# FileName:python_day01
# DateTime:2024/3/17 13:26
# SoftWare: PyCharm
import copy
import keyword

# 输出一个数据
print("Hello World")
# 输出多个数据
print("Hello", "Python", 20, True)

print("hello", "world", sep='----')

# 字符串对齐
print("The value is ljust: |{:5}|".format("abc"))
print("The value is rjust: |{:<5}|".format("abc"))
print("The value is rjust: |{:>5}|".format("abc"))
# 数字对齐
print("The value is rjust: |{:5}|".format(11))
print("The value is rjust: |{:<5}|".format(11))
print("The value is rjust: |{:>5}|".format(11))

print(keyword.kwlist)

print(id("霍格沃兹"))

name = "霍格沃兹"
print(id(name))

school = "霍格沃兹"
print(id(school))

n = 10 + 3.14
print(n, type(n))

n = False + 1
print(n)
print(type(n))

title = "霍格沃兹" + str(666)
print(title, type(title))

b = bool(123)
print(b)
print(type(b))

# a = 666
s = "Hello"
sum1 = 1 + 2
print(sum1)

a = 0
b = 1
c = 2
print(a and b)
print(b and a)
print(a and c)
print(c and a)
print(b and c)
print(c and b)

print(a or c)
print(a or b)
print(b or c)

print("o" in "Hogwarts")
print("K" in "Hogwarts")
print(0 in [1, 2, 3, 4, 5])
print(3 in [1, 2, 3, 4, 5])

print("o" not in "Hogwarts")
print("K" not in "Hogwarts")
print(0 not in [1, 2, 3, 4, 5])
print(3 not in [1, 2, 3, 4, 5])

str1 = "Hello"
str2 = "Hello"
print(id(str1))  # 输出第一个字符串对象的内存地址
print(id(str2))  # 输出第二个字符串对象的内存地址
print(str1 == str2)
print(str1 is str2)

# 示例 2
str3 = "Hello, World!" * 1000
str4 = "Hello, World!" * 1000
print(id(str3))  # 输出第一个字符串对象的内存地址
print(id(str4))  # 输出第二个字符串对象的内存地址
print(str3 == str4)
print(str3 is str4)
print("Hello, World!" * 2)

str1 = "Hello"
str2 = "Hello"
print(id(str1))  # 输出第一个字符串对象的内存地址
print(id(str2))  # 输出第二个字符串对象的内存地址
print(str1 == str2)
print(str1 is not str2)

str3 = "Hello, World!" * 1000
str4 = "Hello, World!" * 1000
print(id(str3))  # 输出第一个字符串对象的内存地址
print(id(str4))  # 输出第二个字符串对象的内存地址
print(str3 == str4)
print(str3 is not str4)

a, b = 1, 1
# 判断a，b 是否相等
print(a == b)
print(a is b)

name = 'asdkjlafkjdshnlkafjhnsdlkfjhalksjdhflkahdsflkahjflkajhsdoiuhafdsouihasofduihaldsuhalufhluhaslufhadsuhf' \
       'asdkbkhjbkjh'

print("|" + "bachogwortsabc".strip("cba") + "|")

print("a\nb\nc".splitlines())
print("a\nb\nc".splitlines(True))

print("This is Hogworts".partition("is"))
print("This is Hogworts".partition("iss"))

stu = {'name': 'Tom', 'age': 23, 'gender': 'male', 'address': 'BeiJing'}
name = stu.pop('name')
print(name)
print(stu)

stu = {'name': 'Tom', 'age': 23, 'gender': 'male', 'address': 'BeiJing'}
ks = stu.keys()
print(ks)

ks = stu.values()
print(ks)

ks = stu.items()
print(ks)

stu = {'name': 'Tom', 'age': 23, 'gender': 'male', 'address': 'BeiJing'}

stu.setdefault("hobby1")
print(stu)
stu.setdefault("hobby2", "无")
print(stu)

ks = ("name", "age", "gender")
s1 = dict.fromkeys(ks)
print(s1)

s2 = dict.fromkeys(ks, "无")
print(s2)

# 更新目标数据是一个字典
stu = {'name': 'Tom', 'age': 23, 'gender': 'male', 'address': 'BeiJing'}
newStu = {"name": "Jack", "hobby": "eat"}
stu.update(newStu)
print(stu)
# 更新目标数据是一个可迭代对象
stu = {'name': 'Tom', 'age': 23, 'gender': 'male', 'address': 'BeiJing'}
newStu = (("name", "Rose"), ["hobby", "play"])
stu.update(newStu)
print(stu)

stu = {'name': 'Tom', 'age': 23, 'gender': 'male', 'address': 'BeiJing'}
v = stu.popitem()
print(v)
print(stu)

v = stu.popitem()
print(v)
print(stu)

# print({}.popitem())


stu = {'name': 'Tom', 'age': 23, 'gender': 'male', 'address': 'BeiJing'}

stu.clear()
print(stu)

stu = {'name': 'Tom', 'age': 23, 'gender': 'male', 'address': 'BeiJing'}
for key in stu.keys():
    print(key)

for val in stu.values():
    print(val)

for item in stu.items():
    print(item)

for key, val in stu.items():
    print(f'{name} = {val}')

s = {1, 2, 3}

print(s.isdisjoint({4, 5, 6}))
print(s.isdisjoint({3, 4, 5}))

a4 = (1, ["李四"])
b4 = copy.deepcopy(a4)
# 查看内存地址
print(id(a4))
print(id(b4))
# 元组里面的可变类型子对象也会进行拷贝
print(id(a4[1]))
print(id(b4[1]))
print(id(a4[0]))
print(id(b4[0]))

for i in range(1, 10):
    for j in range(1, i + 1):
        print(f'{j} * {i} = {i * j}', end='\t')
    print()

t1 = (x for x in range(1, 10))
value1 = next(t1)
print(t1)
for i in t1:
    print(i)


# 不确定个数数字求和
def my_sum(*args):
    print(args)
    print(*args)
    print(type(args))
    s = 0
    for i in args:
        s += i

    print(s)
    print("*" * 10)


my_sum(1, 2, 3)


def print_info(**kwargs):
    print(kwargs)
    print(type(kwargs))
    for k, v in kwargs.items():
        print(k, v)
    print("*" * 10)


print_info(Tom=18, Jim=20, Lily=12)
print_info(name="tom", age=22, gender="male", address="BeiJing")


def info(name1, name2, *args, age1=18, age2=21, **kwargs):
    print("Positional Arguments:")
    print("name1:", name1)
    print("name2:", name2)
    print("args:", args)
    print("Keyword Arguments:")
    print("age1:", age1)
    print("age2:", age2)
    print("kwargs:", kwargs)


info("Alice", "Bob", "Charlie", "Dave", age2=30, occupation="Engineer", city="New York")
info("Alice", "Bob", "Charlie", "Dave", age1=25, age2=30, occupation="Engineer", city="New York")


def fibonacci(n):
    if n <= 0:
        return 0
    if n == 1:
        return 1
    return fibonacci(n - 1) + fibonacci(n - 2)


# 计算斐波那契数列的第 10 项 fibonacci(0) 是第一个数，第十个数就是fibonacci(9)
n = 9
fib_result = fibonacci(9)
print(f"斐波那契数列的第 {n + 1} 项为：{fib_result}")

for i in range(20):
    fib_result = fibonacci(i)
    print(f"斐波那契数列的第 {i + 1} 项为：{fib_result}")


def make_div(func):

    def inner(*args, **kwargs):
        return "<div>" + func() + "</div>"

    return inner


def make_p(func):


    def inner(*args, **kwargs):
        return "<p>" + func() + "</p>"

    return inner


# 装饰过程: 1 content = make_p(content) 2 content = make_div(content)
# content = make_div(make_p(content))
@make_div
@make_p
def content():
    return "人生苦短"


result = content()

print(result)

"""


def decorator_A(func):
    def inner_A():
        print("Entering A")
        func()
        print("Exiting A")

    return inner_A


def decorator_B(func):
    def inner_B():
        print("Entering B")
        func()
        print("Exiting B")

    return inner_B


@decorator_B
@decorator_A
def my_function():
    print("Inside my_function")


# 调用被装饰器装饰的函数
my_function()

a_list = [1, 2]
bl = a_list
print(id(a_list))
print(id(bl))


class A(object):
    # A 继承自 object 根类
    def show(self):
        print("父类A的方法")


class B(A):
    # 子类重写父类方法
    def show(self):
        # 使用 super() 调用父类方法
        super().show()
        print("子类B的方法")


b = B()
# 当子类方法与父类方法同名时，调用子类方法
b.show()


class FA(object):
    def show(self):
        print("FA Show Run...")


class FB(object):
    def show(self):
        print("FB Show Run...")


class S(FB, FA):
    def s_show(self):
        print("S Show Run...")


s = S()
s.s_show()
s.show()
print(S.__mro__)  # 返回该类继承的各个父类之间的继承关系


class FA(object):
    def __init__(self, a):
        self.a = a


class FB(object):
    def __init__(self, b):
        self.b = b


class S(FB, FA):
    def __init__(self, a, b, c):
        super().__init__(b)
        FA.__init__(self, a)
        self.c = c


c = S(1, 2, 3)
print(c.a)
print(c.b)
print(c.c)

name: int = 10
print(id(name))

name = 20
print(id(name))

c = 10
print(id(c))

d = c
print(id(d))


def test1(a):
    print(a)
    print(id(a))
    a += a
    print(a)
    print(id(a))


# int：计算前后id值不同
b = 100
test1(b)
# 列表：计算前后id值相同
c = [11, 22]
test1(c)

for i in range(1, 10):
    for j in range(1, i + 1):
        print(f"{j} * {i} = {i * j}", end="\t")
    print()
